package com.hd.crdao.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hd.crdao.R;
import com.hd.crdao.base.MyBaseAdapter;
import com.hd.crdao.bean.MealListBean;
import com.hd.crdao.utils.UIUtils;

import java.util.List;

/**
 *
 *@author Administrator
 *@date 2017/6/28 0028
 */
public class MealListAdapter extends MyBaseAdapter<MealListBean.DataBean> {


    public MealListAdapter(List<MealListBean.DataBean> dataSets) {
        super(dataSets);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(UIUtils.getContext(), R.layout.item_meal, null);
            //找到控件
            holder.mPrice = (TextView) convertView.findViewById(R.id.price);
            holder.mMeal = (TextView) convertView.findViewById(R.id.tv_meal);
            holder.mData = (TextView) convertView.findViewById(R.id.tv_data);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MealListBean.DataBean dataBean = mDataSets.get(position);

        //设置数据
        holder.mPrice.setText("￥"+dataBean.getSdAmount());
//        holder.mPrice.setText("￥"+0.01);
        holder.mMeal.setText(dataBean.getSdName());
        holder.mData.setText("有效期"+dataBean.getSdTerm()+"天");


        return convertView;
    }

    class ViewHolder {
        TextView mPrice;
        TextView mMeal;
        TextView mData;
    }
}
